package org.abc.fund.entity.funds;

import jakarta.persistence.*;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 基金财务指标实体
 * 从 factorEntity.FundFinIndicator 迁移而来
 * 对应 JoinQuant API: finance.FUND_FIN_INDICATOR
 */
@Entity
@Table(name = "fund_fin_indicator", indexes = {
        @Index(name = "idx_fund_code_stat_date", columnList = "fund_code, statistic_date")
})
@Data
public class FundFinIndicator {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 基金代码
     */
    @Column(name = "fund_code", nullable = false, length = 20)
    private String fundCode;

    /**
     * 统计日期
     */
    @Column(name = "statistic_date", nullable = false)
    private LocalDate statisticDate;

    /**
     * 基金总资产（元）
     */
    @Column(name = "total_asset", precision = 20, scale = 4)
    private BigDecimal totalAsset;

    /**
     * 基金总负债（元）
     */
    @Column(name = "total_liability", precision = 20, scale = 4)
    private BigDecimal totalLiability;

    /**
     * 基金净资产（元）
     */
    @Column(name = "net_asset", precision = 20, scale = 4)
    private BigDecimal netAsset;

    /**
     * 基金份额（份）
     */
    @Column(name = "fund_shares", precision = 20, scale = 4)
    private BigDecimal fundShares;

    /**
     * 期间收益率（%）
     */
    @Column(name = "period_return", precision = 10, scale = 6)
    private BigDecimal periodReturn;

    /**
     * 期间净值增长率（%）
     */
    @Column(name = "nav_growth_rate", precision = 10, scale = 6)
    private BigDecimal navGrowthRate;

    /**
     * 数据采集时间
     */
    @Column(name = "collected_at", nullable = false)
    private LocalDateTime collectedAt;

    @PrePersist
    protected void onCreate() {
        if (collectedAt == null) {
            collectedAt = LocalDateTime.now();
        }
    }
}





















